package cb;
import static org.jhotdraw.draw.AttributeKeys.END_DECORATION;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import javax.swing.Action;
import javax.swing.JToolBar;

import org.jhotdraw.app.Application;
import org.jhotdraw.app.DefaultApplicationModel;
import org.jhotdraw.app.DefaultMDIApplication;
import org.jhotdraw.app.Project;
import org.jhotdraw.draw.ArrowTip;
import org.jhotdraw.draw.AttributedFigure;
import org.jhotdraw.draw.BezierFigure;
import org.jhotdraw.draw.BezierTool;
import org.jhotdraw.draw.ConnectionFigure;
import org.jhotdraw.draw.ConnectionTool;
import org.jhotdraw.draw.CreationTool;
import org.jhotdraw.draw.DiamondFigure;
import org.jhotdraw.draw.DrawingEditor;
import org.jhotdraw.draw.ElbowLiner;
import org.jhotdraw.draw.EllipseFigure;
import org.jhotdraw.draw.GridConstrainer;
import org.jhotdraw.draw.LineConnectionFigure;
import org.jhotdraw.draw.LineFigure;
import org.jhotdraw.draw.RectangleFigure;
import org.jhotdraw.draw.RoundRectangleFigure;
import org.jhotdraw.draw.TextAreaFigure;
import org.jhotdraw.draw.TextAreaTool;
import org.jhotdraw.draw.TextFigure;
import org.jhotdraw.draw.TextTool;
import org.jhotdraw.draw.TriangleFigure;
import org.jhotdraw.draw.action.ToolBarButtonFactory;
import org.jhotdraw.samples.draw.DrawApplicationModel;
import org.jhotdraw.samples.draw.DrawProject;
import org.jhotdraw.util.ResourceBundleUtil;

import cb.tools.CurrentSource;

import cb.tools.GroundFigure;
import cb.tools.JunctionFigure;
import cb.tools.CustomNodeFigure;
import cb.tools.LabelTool;
import cb.tools.ResistorFigure;
import cb.tools.VoltageSource;
import cb.tools.WireTool;


@SuppressWarnings("unused")
public class CircuitBuilder extends DrawApplicationModel
	{
		public static void main(String[] args)
			{
				Application app;
				app = new CustomMDIApplication();
				CircuitBuilder model = new CircuitBuilder();
				model.setName("JHotDraw CircuitBuilder");
				model.setVersion("0");
				model.setCopyright("broken");
				model.setProjectClassName("org.jhotdraw.samples.draw.DrawProject");
				app.setModel(model);
				app.launch(args);
			}
		
		private static final long serialVersionUID = 1L;

		public CircuitBuilder()
			{
				super();
			}

		@Override
		public List<JToolBar> createToolBars(Application a, Project pr)
			{
				ResourceBundleUtil labels = ResourceBundleUtil
						.getLAFBundle("org.jhotdraw.draw.Labels");
				DrawProject p = (DrawProject) pr;

				DrawingEditor editor;
				if (p == null)
					{
						editor = getSharedEditor();
					} else
					{
						editor = p.getEditor();
					}

				LinkedList<JToolBar> list = new LinkedList<JToolBar>();
				JToolBar tb;

				tb = new JToolBar();
				addCreationButtonsTo(tb, editor);
				tb.setName(labels.getString("drawToolBarTitle"));
				list.add(tb);
//				
//				tb = new JToolBar();
//				addCreationButtonsTo(tb, editor);
//				tb.setName(labels.getString("dToolBarTitle"));
//				list.add(tb);

//				tb = new JToolBar();
//				ToolBarButtonFactory.addAttributesButtonsTo(tb, editor);
//				tb.setName(labels.getString("attributesToolBarTitle"));
//				list.add(tb);
//
//				tb = new JToolBar();
//				ToolBarButtonFactory.addAlignmentButtonsTo(tb, editor);
//				tb.setName(labels.getString("alignmentToolBarTitle"));
//				list.add(tb);

				return list;
			}

		private void addCreationButtonsTo(JToolBar tb, DrawingEditor editor)
			{
				addDefaultCreationButtonsTo(tb, editor,
						ToolBarButtonFactory.createDrawingActions(editor),
						ToolBarButtonFactory.createSelectionActions(editor));
			}

		private void addCreationButtonsTo2(JToolBar tb, DrawingEditor editor)
			{
				addDefaultCreationButtons2To(tb, editor,
						ToolBarButtonFactory.createDrawingActions(editor),
						ToolBarButtonFactory.createSelectionActions(editor));
			}
		
		@Override
		public void addDefaultCreationButtonsTo(JToolBar tb,
				final DrawingEditor editor, Collection<Action> drawingActions,
				Collection<Action> selectionActions)
			{
				ResourceBundleUtil labels = ResourceBundleUtil
						.getLAFBundle("org.jhotdraw.draw.Labels");
				//custom labels for our project are in a different source which I put in the  package
				//referenced below
				ResourceBundleUtil customlabels = ResourceBundleUtil
						.getLAFBundle("cb.properties.Labels");

				ToolBarButtonFactory.addSelectionToolTo(tb, editor,
						drawingActions, selectionActions);
				tb.addSeparator();

				AttributedFigure af;
				CreationTool ct;
				ConnectionTool cnt;
				ConnectionFigure lc;
				//resistor icon located in customlabels
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new ResistorFigure()), "createResistor", customlabels);
				//junction
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new JunctionFigure()), "createJunction", customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new TextTool(
						new LabelTool()), "createLabel", customlabels);

				ToolBarButtonFactory.addToolTo(tb, editor,
						cnt = new ConnectionTool(new WireTool()),
						"createWire", customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new VoltageSource()), "addVS",
						customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new CurrentSource()), "addCurrentSource",
						customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new GroundFigure()), "createGround",
						customlabels);
				
				lc = cnt.getPrototype();
				lc.setLiner(new ElbowLiner());
			}
		
		public void addDefaultCreationButtons2To(JToolBar tb,
				final DrawingEditor editor, Collection<Action> drawingActions,
				Collection<Action> selectionActions)
			{
				ResourceBundleUtil labels = ResourceBundleUtil
						.getLAFBundle("org.jhotdraw.draw.Labels");
				//custom labels for our project are in a different source which I put in the  package
				//referenced below
				ResourceBundleUtil customlabels = ResourceBundleUtil
						.getLAFBundle("cb.properties.Labels");

				ToolBarButtonFactory.addSelectionToolTo(tb, editor,
						drawingActions, selectionActions);
				tb.addSeparator();

				AttributedFigure af;
				CreationTool ct;
				ConnectionTool cnt;
				ConnectionFigure lc;
				//resistor icon located in customlabels
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new ResistorFigure()), "createResistor", customlabels);
				//junction
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new JunctionFigure()), "createJunction", customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new TextTool(
						new LabelTool()), "createLabel", customlabels);

				ToolBarButtonFactory.addToolTo(tb, editor,
						cnt = new ConnectionTool(new WireTool()),
						"createWire", customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new VoltageSource()), "addVS",
						customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new CurrentSource()), "addCurrentSource",
						customlabels);
				
				ToolBarButtonFactory.addToolTo(tb, editor, new CreationTool(
						new GroundFigure()), "createGround",
						customlabels);
				
				lc = cnt.getPrototype();
				lc.setLiner(new ElbowLiner());
			}

		
	}
